package com.example.demo.enums;

import lombok.Getter;

import java.util.Arrays;

@Getter
public enum BookStatusEnum {
    DELETED(0, "删除"),
    NORMAL(1, "可借阅"),
    FORBIDDEN(2, "不可借阅");

    private Integer code;
    private String desc;

    BookStatusEnum(Integer code, String desc) {
        this.code = code;
        this.desc = desc;
    }

    public static BookStatusEnum getStatusByCode(Integer code){
        //第一种 :if else
//        if(code == 0){
//            return BookStatusEnum.DELETED;
//        }else if(){
//            ....
//        }

        //第二种: switch
//        switch(code){
//            case 0: ....
//        }

        //第三种: lambda
        return Arrays.stream(BookStatusEnum.values()).filter(status -> status.getCode() == code).findFirst().get();
    }
}
